unit udmsrv;

{$mode ObjFPC}{$H+}

interface

uses
  Classes,
  SysUtils,
  Dialogs,
  gettext,
  DefaultTranslator,
  LCLTranslator,
  mormot.DB.sql,
  mormot.DB.sql.sqlite3,
  mormot.DB.raw.sqlite3,
  mormot.DB.raw.sqlite3.static,
  ExtCtrls,
  Menus,
  UniqueInstance,
  IdHTTPServer,
  IdCustomTCPServer,
  IdContext,
  IdCustomHTTPServer;

type

  { Tdmsrv }

  Tdmsrv = class(TDataModule)
    idhs: TIdHTTPServer;
    pm: TPopupMenu;
    ti: TTrayIcon;
    ui: TUniqueInstance;
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
    procedure idhsCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
      AResponseInfo: TIdHTTPResponseInfo);
    procedure tiDblClick(Sender: TObject);
  private

  public

  end;

var
  dmsrv: Tdmsrv;
  gPath: string;
  gProps: TSqlDBSQLite3ConnectionProperties;

implementation

{$R *.lfm}

{ Tdmsrv }
uses
  ufrmmain,
  uConst;

procedure Tdmsrv.DataModuleCreate(Sender: TObject);
begin
  idhs.Active := True;
end;

procedure Tdmsrv.DataModuleDestroy(Sender: TObject);
begin
  idhs.Active := False;
end;

procedure Tdmsrv.idhsCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
  AResponseInfo: TIdHTTPResponseInfo);
begin
  with ARequestInfo do if Document = '/' then
      begin
      dolog(strRequestGet, [RemoteIP, Document]);
      AResponseInfo.ContentType := 'text/html;charset=utf-8';
      AResponseInfo.ContentStream :=
        TFileStream.Create('.\wwwroot\index.html', fmOpenReadWrite);
      end;
end;

procedure Tdmsrv.tiDblClick(Sender: TObject);
begin
  if frmmain.Showing then
    frmmain.Hide
  else
    frmmain.ShowOnTop;
end;

initialization

finalization
end.
